package com.shangyitong.yygh_user.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shangyitong.ResultCodeEnum;
import com.shangyitong.exception.UserException;
import com.shangyitong.yygh.model.user.Patient;
import com.shangyitong.yygh_user.mapper.PatientMapper;
import com.shangyitong.yygh_user.service.PatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@Slf4j
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Override
    public void savePatient(Patient patient, Long userId) {
        if (userId == null) {
            throw new UserException(ResultCodeEnum.LOGIN_AUTH);
        }
        patient.setUserId(userId);
        if (!StringUtils.isEmpty(patient.getContactsName())) {
            patient.setContactsName(patient.getContactsName());
        }
        if (!StringUtils.isEmpty(patient.getContactsPhone())) {
            patient.setContactsPhone(patient.getContactsPhone());
        }
        if (!StringUtils.isEmpty(patient.getContactsCertificatesType())) {
            patient.setContactsCertificatesType(patient.getContactsCertificatesType());
        }
        if (!StringUtils.isEmpty(patient.getContactsCertificatesNo())) {
            patient.setContactsCertificatesNo(patient.getContactsCertificatesNo());
        }
        baseMapper.insert(patient);
    }
}
